﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace DemoGraphics2D
{
    class My2DSprite
    {
        private Bitmap[] _Bmp;

        public Bitmap[] Bmp
        {
            get { return _Bmp; }
            set 
            { 
                _Bmp = value;
                _nBmp = _Bmp.Length;
                _iBmp = 0;
                for (int i = 0; i < _nBmp; i++)
                    _Bmp[i].MakeTransparent(_Bmp[i].GetPixel(_Bmp[i].Width - 1,_Bmp[i].Height - 1));
            }
        }

        private int _nBmp;

        public int nBmp
        {
            get { return _nBmp; }
            set { _nBmp = value; }
        }

        private int _iBmp;

        public int iBmp
        {
            get { return _iBmp; }
            set { _iBmp = value; }
        }

        private int _Top;

        public int Top
        {
            get { return _Top; }
            set { _Top = value; }
        }

        private int _Left;

        public int Left
        {
            get { return _Left; }
            set { _Left = value; }
        }

        private int _Width;

        public int Width
        {
            get { return _Width; }
            set { _Width = value; }
        }

        private int _Height;

        public int Height
        {
            get { return _Height; }
            set { _Height = value; }
        }

        public My2DSprite(Bitmap[] _bmp, int _top, int _left, int _width, int _height)
        {
            Bmp = _bmp;
            Top = _top;
            Left = _left;
            Width = _width;
            Height = _height;
        }

        private int _state = 0;

        public int state
        {
            get { return _state; }
            set 
            { 
                _state = value;
                delta = 0;
                ddelta = 1;
            }
        }

        public void Draw(Graphics g)
        {
            if (_state == 0)
            {
                g.DrawImage(_Bmp[_iBmp], _Left, _Top);
            }
            else
            {
                g.DrawImage(_Bmp[_iBmp], _Left - delta, _Top - delta, Width + 2 * delta, Height + 2 * delta);
            }
        }

        public int delta = 0;
        public int ddelta = 1;

        public void Update()
        {
            _iBmp = (_iBmp + 1) % _nBmp;
            delta += ddelta;
            if (delta > 10 || delta < -10)
                ddelta *= -1;
        }

        internal bool IsClicked(int x, int y)
        {
            if (Left - delta <= x && x <= Left + Width + delta && Top - delta <= y && y <= Top + Height + delta)
                return true;
            return false;
        }
    }
}
